/**
 * 
 */
package com.cdhospital.admincontroller;

import com.cdhospital.Model.Department;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

/**
 * @author 17994
 *
 */
public class AdminDepartmentController extends Controller {
	
	public void index(){
		Integer pageNumber=getParaToInt("pageNumber");
		if(pageNumber==null){
			pageNumber=1;
		}
		Page<Record> department=Db.paginate(1, 10, "select * ", "from department  order  by did asc");
		setAttr("department", department);
		render("index.html");
	}
	public void form(){	
		Integer id=getParaToInt("id");
		if (id!=null && id>0) {
			setAttr("department", Department.dao.findById(id));
		}
		
		render("info.html");
	}
	public void delect(){
		Integer id=getParaToInt("id");
		if (id!=null && id>0) {
			boolean flag=Department.dao.deleteById(id);
			if (!flag) {
				renderText("删除失败");
				setAttr("err", 2);
				return;
			}
			
		}
		else {
			renderText("删除失败");
			setAttr("err", 2);
			return;
		}
		
		   renderJson();
	}
	public void save (){
		Department department=getModel(Department.class,"department");
		if (department.get("did")==null) {
			department.save();
			
		}
		else if (department.getInt("did")>0) {
			department.update();
		}
		redirect("/admin/department");
		
	}


}
